<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<!--导入easyui样式 -->
<link rel="stylesheet"
	href="${pageContext.request.contextPath}/themes/bootstrap/easyui.css" />
<link rel="stylesheet"
	href="${pageContext.request.contextPath}/themes/icon.css" />
<script type="text/javascript"
	src="${pageContext.request.contextPath}/js/jquery-1.9.1.js"></script>
<script type="text/javascript"
	src="${pageContext.request.contextPath}/js/jquery.easyui.min.js"></script>
<script type="text/javascript"
	src="${pageContext.request.contextPath}/js/easyui-lang-zh_CN.js"></script>
</head>
<script type="text/javascript">
$(function(){
	$('#dg').datagrid({
			url:'cccx',
			columns:[[  
					{field:'ck',checkbox:true,width:100,align:'center'},       
				    {field:'cid',title:'课程编号',width:100,align:'center'},    
				    {field:'cname',title:'课程名称',width:100,align:'center'},    
				    {field:'classtime',title:'上课时间',width:100,align:'center'},
				    {field:'place',title:'上课地点',width:100,align:'center'},
				    {field:'tname',title:'教师',width:100,align:'center'},			    
			]],
			pageSize:5,
		    pagePosition:'bottom',
		    pagination:true,
		    pageList:[5,6,7],
		    rownumbers:true,
		    toolbar: [{
				iconCls: 'icon-edit',
				text:'修改课程信息',
				handler: function(){
					var  tea = $('#dg').datagrid('getSelections');	
					if(tea.length==1){
						$("#updatec").dialog("open").dialog('setTitle', '修改课程信息');
						var cname1 = tea[0].cname;
						$("#cc2").combo('setText',cname1);
						var time1 = tea[0].classtime;
						$("#ss1").timespinner('setValue',time1);
						$("#place1").val(tea[0].place);
						var tname1 = tea[0].tname;
						$("#cc1").combo('setText',tname1);						
						$("#save1").linkbutton({
							onClick:function(){
								var cid1 = tea[0].cid;
								var cname1 = $("#cc2").combo('getText');
								var classtime1 = $("#ss1").timespinner('getValue');
								var place1 = $("#place1").val();
								var tname1 = $("#cc1").combo('getText');
								$.ajax({
									url:'updatec',	
									type:'post',
									data:{'cid':cid1,'cname':cname1,'classtime':classtime1,'place':place1,'tname':tname1},
									datatype:'text',
									success:function(data){
										if(data=="1"){
											$.messager.alert('success','修改成功！','info');
											$("#updatec").dialog("close");
											$('#dg').datagrid('reload');
										}else{
											$.messager.alert('error','修改失败！','info');
											$("#updatec").dialog("close");
											$('#dg').datagrid('reload');
										}
									}
									
								})
							}
						})
					}else{
						$.messager.alert('error','请只选择一个！','info');	
					}
					//修改取消按钮
					$("#cancel1").linkbutton({
						onClick:function(){
							$("#updatec").dialog("close");
							$('#dg').datagrid('uncheckAll');
						}
					})
				}
			},'-',{
				iconCls: 'icon-add',
				text:'新增课程',
				handler: function(){
					$("#insertc").dialog("open").dialog('setTitle', '新增课程'); 
					$("#cname").val("");  //使得新增窗口弹出都为空
					$("#ss").timespinner('setValue','');
					$("#place").val("");
					$("#cc").combo('setText','');
					$('#cc').combobox({    
						panelHeight:250 
					});
					$("#save").linkbutton({
						onClick:function(){
							var cname = $("#cname").val();
							var classtime = $("#ss").timespinner('getValue');
							var place = $("#place").val();
							var tname = $("#cc").combo('getText'); 
							$.ajax({
								url:'insertcourse',
								type:'post',
								data:{'cname':cname,'classtime':classtime,'place':place,'tname':tname},
								datatype:'text',
								success:function(data){
									if(data=="1"){
										$.messager.alert('success','添加成功！','info');
										$("#cname").val("");
										$("#ss").timespinner('setValue','');
										$("#place").val("");
										$("#cc").combo('setText','');
										$("#insertc").dialog("close");
										$('#dg').datagrid('reload');
									}else{
										$.messager.alert('error','添加失败！','info');
										$("#insertc").dialog("close");
									}
								}
							})
						}
					})
					//新增取消
			$("#cancel").linkbutton({
				onClick:function(){
						$("#cname").val("");
						$("#classtime").val("");
						$("#place").val("");
						$("#cc").combo('setText','');
						$("#insertc").dialog("close");
						$('#dg').datagrid('uncheckAll');
								}
							})
				}
			},'-',{
				iconCls: 'icon-remove',
				text:'删除课程',
				handler: function(){
					var ck = $('#dg').datagrid('getSelections');					
					if(ck.length>0){
						$("#deletecourse").dialog("open").dialog('setTitle', '删除课程');
						$("#yes").linkbutton({
							onClick:function(){
								var cid = [];
								for (var i = 0; i < ck.length; i++) {
									cid.push(ck[i].cid);
								}
								$.ajax({
									url:'deletecourse',
									type:'post',
									data:{'cid':cid},
									datatype:'text',
									success:function(data){
										if(data=='1'){
											$.messager.alert('success','删除成功！','info');
											$("#deletecourse").dialog("close");
											$('#dg').datagrid('reload');
										}else{
											$.messager.alert('error','删除失败！','info');
											$("#deletecourse").dialog("close");
											$('#dg').datagrid('reload');
										}
									}
								})	
								
							}
						})
					}else{
						$.messager.alert('MSG','请至少选择一个！','info');
					}
					$("#no").linkbutton({
						onClick:function(){
							$('#dg').datagrid('uncheckAll');
							$("#deletetea").dialog("close");
							}
						})
				}
			}]

	})	
	//新增课程教师下拉列表框
	$('#cc').combobox({    
	    url:'findtea',    
	    valueField:'id',    
	    textField:'text'   
	}); 
	//修改课程教师下拉列表框
	$('#cc1').combobox({    
	    url:'findtea1',    
	    valueField:'id',    
	    textField:'text'   
	}); 
	//修改课程课程下拉列表框
	$('#cc2').combobox({    
	    url:'findcourse',    
	    valueField:'id',    
	    textField:'text'   
	}); 
	//时间微调框--新增课程
	$('#ss').timespinner({    
	    min: '08:30',    
	    required: true,    
	    showSeconds: false   
	});
	//时间微调框  --修改课程信息
	$('#ss1').timespinner({    
	    min: '08:30',    
	    required: true,    
	    showSeconds: false   
	});
})		
	
</script>
<body>
	 <table id="dg"></table>
	  <!--新增彈出窗口 -->
  <div id="insertc" class="easyui-dialog"  closed="true" buttons="#dlg1-buttons" > 
	<div  style="width: 250px;height: 200px;margin-top: 30px;margin-left: 30px">
            课程名称<input id="cname" name="cname" class="easyui-validatebox"  /><br><br>    
            上课时间<input id="ss" style="width:80px;"><br><br>
            上课地点<input id="place" name="place" class="easyui-validatebox"  /><br><br>
        <div class="easyui-layout" data-options="fit:true">  
          教&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;师<input class="easyui-combobox" id="cc" name="cc" style="width:100px" value="古月" /> 
          </div> 
    </div>
    <div id="dlg1-buttons">
        <button id="save"  class="easyui-linkbutton"  iconcls="icon-save">确认</button>
        <button id="cancel" class="easyui-linkbutton" iconcls="icon-cancel">取消</button>
    </div>
   </div> 
   <!--修改彈出窗口 -->
  <div id="updatec" class="easyui-dialog"  closed="true" buttons="#dlg2-buttons" > 
	<div  style="width: 250px;height: 200px;margin-top: 30px;margin-left: 30px">     
         课程名称<input class="easyui-combobox" id="cc2" name="cc2" style="width:100px"  /> 
          <br><br>   
            上课时间<input id="ss1" style="width:80px;"><br><br>     
            上课地点<input id="place1" name="place1" class="easyui-validatebox"  /><br><br>
        <div class="easyui-layout" data-options="fit:true">  
          教&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;师<input class="easyui-combobox" id="cc1" name="cc1" style="width:100px"  /> 
          </div> 
    </div>
    <div id="dlg2-buttons">
        <button id="save1"  class="easyui-linkbutton"  iconcls="icon-save">确认</button>
        <button id="cancel1" class="easyui-linkbutton" iconcls="icon-cancel">取消</button>
    </div>
   </div> 
	  <!-- 删除彈出窗口 -->
  		<div id="deletecourse" class="easyui-dialog"  closed="true" buttons="#dlg3-buttons" > 
		 <div  style="width: 100px;height: 30px;margin-top: 10px;margin-left: 30px">
	  		<p>确认删除吗？</p>
	  	 </div>
       <div id="dlg3-buttons">
        <button id="yes"  class="easyui-linkbutton"  iconcls="icon-save">确认</button>
        <a id="no" class="easyui-linkbutton" onclick="javascript:$('#deletecourse').dialog('close')"
         iconcls="icon-cancel">取消</a>
        </div>
        </div>
</body>
</html>